using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace App
{
    public class Pan : System.Windows.Forms.Panel
    {
        private System.ComponentModel.Container components = null;
        private Color m_ColorLeftTop = Color.FromArgb(248, 255, 255);
        private Color m_ColorRightBotton = Color.FromArgb(218, 234, 255);
        private Color m_ColorPanBorder = Color.FromArgb(141, 178, 227);
        private Color m_ColorBorder = Color.FromArgb(155, 0, 0, 0);
        private bool m_DrawTop = false;
        private bool m_DrawButton = false;

        public Pan()
        {
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        }

        [Description("Draw Top Line")]
        [System.ComponentModel.RefreshProperties(RefreshProperties.Repaint)]
        public bool ColorDrawTop
        {
            get
            {
                return m_DrawTop;
            }
            set
            {
                m_DrawTop = value;
            }
        }

        [Description("Draw Botton Line")]
        [System.ComponentModel.RefreshProperties(RefreshProperties.Repaint)]
        public bool ColorDrawButton
        {
            get
            {
                return m_DrawButton;
            }
            set
            {
                m_DrawButton = value;
            }
        }

        [Description("Line Border")]
        [System.ComponentModel.RefreshProperties(RefreshProperties.Repaint)]
        public Color ColorBorder
        {
            get
            {
                return m_ColorBorder;
            }
            set
            {
                m_ColorBorder = value;
            }
        }

        [Description("Top-Left Color")]
        [System.ComponentModel.RefreshProperties(RefreshProperties.Repaint)]
        public Color ColorLeftTop
        {
            get
            {
                return m_ColorLeftTop;
            }
            set
            {
                m_ColorLeftTop = value;
            }
        }

        [Description("Right-Botton Color")]
        [System.ComponentModel.RefreshProperties(RefreshProperties.Repaint)]
        public Color ColorRightBotton
        {
            get
            {
                return m_ColorRightBotton;
            }
            set
            {
                m_ColorRightBotton = value;
            }
        }

        [Description("Draw Backgroud LinearGradient")]
        [System.ComponentModel.RefreshProperties(RefreshProperties.Repaint)]
        public bool DrawBackgroud { get; set; }

        [Description("Draw Border")]
        [System.ComponentModel.RefreshProperties(RefreshProperties.Repaint)]
        public bool DrawBorder { get; set; }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (ClientRectangle.Width == 0 || ClientRectangle.Height == 0)
                return;

            Pen pen = new Pen(this.m_ColorPanBorder);

            if (DrawBackgroud)
            {
                System.Drawing.Drawing2D.LinearGradientBrush br = new
                    System.Drawing.Drawing2D.LinearGradientBrush(ClientRectangle,
                    ColorLeftTop, m_ColorRightBotton,
                    System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal);
                e.Graphics.FillRectangle(br, ClientRectangle);
                br.Dispose();
            }

            if (DrawBorder && ClientRectangle != null && ClientRectangle.Width > 1 && ClientRectangle.Height > 1)
            {
                e.Graphics.DrawRectangle(pen,
                    ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
                pen.Dispose();
            }
            else
            {
                if (this.m_DrawTop)
                {
                    e.Graphics.DrawLine(pen,
                        ClientRectangle.X,
                        ClientRectangle.Y,
                        ClientRectangle.X + ClientRectangle.Width,
                        ClientRectangle.Y);
                }
                //
                if (this.m_DrawButton)
                {
                    e.Graphics.DrawLine(pen,
                        ClientRectangle.X,
                        ClientRectangle.Y + ClientRectangle.Height - 1,
                        ClientRectangle.X + ClientRectangle.Width,
                        ClientRectangle.Y + ClientRectangle.Height - 1);
                }
            }
            
            pen.Dispose();
            //for (int i = 0; i < this.Controls.Count; i++)
            //{
            //    if (this.Controls[i].Name.StartsWith("txt"))
            //    {
            //        DrawHelper.DrawShadow(e.Graphics, this.Controls[i].Bounds);
            //    }
            //}
        }

    }
}
